package com.kkb.service.dataanalysis.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.bean.AnthologyTable;
import com.kkb.bean.FileAnthologyTable;
import com.kkb.bean.FileTable;
import com.kkb.bean.User;
import com.kkb.dao.AnthologyTableMapper;
import com.kkb.dao.FileAnalysisMapper;
import com.kkb.dao.FileAnthologyTableMapper;
import com.kkb.dao.FileTableMapper;
import com.kkb.service.dataanalysis.ProductAnalysisService;
import com.kkb.vo.dataanalysis.ProductSaleVo;
import com.kkb.vo.dataanalysis.req.FileReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mj
 * @create 2021-04-14 16:51
 * @describe:
 */
@Service
@Slf4j
public class ProductAnalysisServiceImpl implements ProductAnalysisService {

    @Autowired
    private FileTableMapper fileTableMapper;

    @Autowired
    private FileAnthologyTableMapper fileAnthologyTableMapper;

    @Autowired
    private AnthologyTableMapper anthologyTableMapper;

    @Override
    public Map<String, Object> productOverview(User user) {
        Map<String,Object> map = new HashMap<>();


        log.info("查询userid:{}的在售文档",user.getUserId());
        FileTable fileTable = new FileTable();
        fileTable.setUserId(user.getUserId());
        //商品上架
        fileTable.setState(1);
        List<FileTable> fileTables = this.fileTableMapper.select(fileTable);

        log.info("查询userid:{}的在售文集",user.getUserId());
        AnthologyTable anthologyTable = new AnthologyTable();
        anthologyTable.setUserId(user.getUserId());
        anthologyTable.setState(1);
        List<AnthologyTable> anthologyTableList = anthologyTableMapper.select(anthologyTable);

        //在售商品的数量
        map.put("productTotalNum",anthologyTableList.size()+fileTables.size());
        //在售文档的数量
        map.put("fileTotalNum",fileTables.size());
        //在售文集的数量
        map.put("anthologyTotalNum",anthologyTableList.size());

        return map;
    }

    /**
     * 查询文档商品效果
     * @param user
     * @param fileReq
     * @return
     */
    @Override
    public Map<String, Object> fileMsg(User user, FileReq fileReq) {
        Map<String,Object> map = new HashMap<>();
        fileReq.setUserId(user.getUserId());
        PageHelper.startPage(fileReq.getPageNum(),fileReq.getPageSize());
        List<ProductSaleVo> productSaleVoList = fileAnthologyTableMapper.fileMsg(fileReq);
        PageInfo<ProductSaleVo> productSaleVoPageInfo = new PageInfo<>(productSaleVoList);
        map.put("data",productSaleVoPageInfo);
        return map;
    }

    /**
     * 查询文集商品效果
     * @param user
     * @param fileReq
     * @return
     */
    @Override
    public Map<String, Object> fileAnthologyMsg(User user, FileReq fileReq) {
        Map<String,Object> map = new HashMap<>();
        fileReq.setUserId(user.getUserId());
        PageHelper.startPage(fileReq.getPageNum(),fileReq.getPageSize());
        List<ProductSaleVo> productSaleVoList = fileAnthologyTableMapper.fileAnthologyMsg(fileReq);
        PageInfo<ProductSaleVo> productSaleVoPageInfo = new PageInfo<>(productSaleVoList);
        map.put("data",productSaleVoPageInfo);
        return map;
    }
}
